﻿using Web.API.IBLL;
using Web.API.IDAL;
using Web.API.Model;

namespace Web.API.BLL
{
    public class UserBLL:UserIBLL
    {
        public UserBLL(MemberIDAL<UserModel> dal) 
        {
            Dal = dal;
        }
        public MemberIDAL<UserModel> Dal { get;}

        public Task<int> AddUser(UserModel user)
        {
           return Dal.AddAsync(user);
        }

        public UserModel Login(string name, string pos)
        {
            var u = Dal.GetAllAsync().FirstOrDefault(x=>x.Name==name);
            if (name == null)
            {
                u = new UserModel {Id=-1 };
            }
            else
            {
                if (u.Pos != pos)
                {
                    u = new UserModel {Id=-2 };
                }
            }
            return u;
        }
        
    }
}
